//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "BinomialProbabilityOfAtLeastNEvents.h"
using namespace Cephei::QL::Experimental::Credit;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Experimental::Credit::CBinomialProbabilityOfAtLeastNEvents::CBinomialProbabilityOfAtLeastNEvents (Int32 n) 
{
	_pSpinlock = new boost::detail::spinlock ();
    try
    {
#ifdef HANDLE
        _phBinomialProbabilityOfAtLeastNEvents = NULL;
#endif
        int _n = (int)ValueHelper::Convert (n);
        _ppBinomialProbabilityOfAtLeastNEvents = new boost::shared_ptr<QuantLib::BinomialProbabilityOfAtLeastNEvents> (new QuantLib::BinomialProbabilityOfAtLeastNEvents ( _n ));
        
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Experimental::Credit::CBinomialProbabilityOfAtLeastNEvents::CBinomialProbabilityOfAtLeastNEvents (boost::shared_ptr<QuantLib::BinomialProbabilityOfAtLeastNEvents>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phBinomialProbabilityOfAtLeastNEvents = NULL;
#endif
	_ppBinomialProbabilityOfAtLeastNEvents = &childNative;
    
}
Cephei::QL::Experimental::Credit::CBinomialProbabilityOfAtLeastNEvents::CBinomialProbabilityOfAtLeastNEvents (QuantLib::BinomialProbabilityOfAtLeastNEvents& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phBinomialProbabilityOfAtLeastNEvents = NULL;
#endif
	_ppBinomialProbabilityOfAtLeastNEvents = new boost::shared_ptr<QuantLib::BinomialProbabilityOfAtLeastNEvents> (&childNative);
    
    _BinomialProbabilityOfAtLeastNEventsOwner = owner;
    
}

Cephei::QL::Experimental::Credit::CBinomialProbabilityOfAtLeastNEvents::CBinomialProbabilityOfAtLeastNEvents (CBinomialProbabilityOfAtLeastNEvents^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phBinomialProbabilityOfAtLeastNEvents = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppBinomialProbabilityOfAtLeastNEvents = new boost::shared_ptr<QuantLib::BinomialProbabilityOfAtLeastNEvents> (copy->GetShared());
        
    }
}
Cephei::QL::Experimental::Credit::CBinomialProbabilityOfAtLeastNEvents::CBinomialProbabilityOfAtLeastNEvents (System::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phBinomialProbabilityOfAtLeastNEvents = NULL;
#endif
	if (!t->IsSubclassOf(CBinomialProbabilityOfAtLeastNEvents::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Experimental::Credit::CBinomialProbabilityOfAtLeastNEvents::CBinomialProbabilityOfAtLeastNEvents (QuantLib::Handle<QuantLib::BinomialProbabilityOfAtLeastNEvents>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phBinomialProbabilityOfAtLeastNEvents = &childNative;
	_ppBinomialProbabilityOfAtLeastNEvents = &static_cast<boost::shared_ptr<QuantLib::BinomialProbabilityOfAtLeastNEvents>>(childNative.currentLink());
    
    _BinomialProbabilityOfAtLeastNEventsOwner = owner;
}
Cephei::QL::Experimental::Credit::CBinomialProbabilityOfAtLeastNEvents::CBinomialProbabilityOfAtLeastNEvents (QuantLib::Handle<QuantLib::BinomialProbabilityOfAtLeastNEvents> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phBinomialProbabilityOfAtLeastNEvents = &childNative;
	_ppBinomialProbabilityOfAtLeastNEvents = &static_cast<boost::shared_ptr<QuantLib::BinomialProbabilityOfAtLeastNEvents>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Experimental::Credit::CBinomialProbabilityOfAtLeastNEvents::CBinomialProbabilityOfAtLeastNEvents (QuantLib::BinomialProbabilityOfAtLeastNEvents childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phBinomialProbabilityOfAtLeastNEvents = NULL;
#endif
	_ppBinomialProbabilityOfAtLeastNEvents = new boost::shared_ptr<QuantLib::BinomialProbabilityOfAtLeastNEvents> (new QuantLib::BinomialProbabilityOfAtLeastNEvents (childNative));
    
}
#endif

Cephei::QL::Experimental::Credit::CBinomialProbabilityOfAtLeastNEvents::~CBinomialProbabilityOfAtLeastNEvents ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppBinomialProbabilityOfAtLeastNEvents != NULL)
    {
	    delete _ppBinomialProbabilityOfAtLeastNEvents;
        _ppBinomialProbabilityOfAtLeastNEvents = NULL;
    }
}
Cephei::QL::Experimental::Credit::CBinomialProbabilityOfAtLeastNEvents::!CBinomialProbabilityOfAtLeastNEvents ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppBinomialProbabilityOfAtLeastNEvents != NULL)
    {
	    delete _ppBinomialProbabilityOfAtLeastNEvents;
    }
}
QuantLib::BinomialProbabilityOfAtLeastNEvents& Cephei::QL::Experimental::Credit::CBinomialProbabilityOfAtLeastNEvents::GetReference ()
{
    if (_ppBinomialProbabilityOfAtLeastNEvents == NULL) throw gcnew NativeNullException ();
	return **_ppBinomialProbabilityOfAtLeastNEvents;
}
boost::shared_ptr<QuantLib::BinomialProbabilityOfAtLeastNEvents>& Cephei::QL::Experimental::Credit::CBinomialProbabilityOfAtLeastNEvents::GetShared ()
{
    if (_ppBinomialProbabilityOfAtLeastNEvents == NULL) throw gcnew NativeNullException ();
	return *_ppBinomialProbabilityOfAtLeastNEvents;
}
QuantLib::BinomialProbabilityOfAtLeastNEvents* Cephei::QL::Experimental::Credit::CBinomialProbabilityOfAtLeastNEvents::GetPointer ()
{
    if (_ppBinomialProbabilityOfAtLeastNEvents == NULL) throw gcnew NativeNullException ();
	return &**_ppBinomialProbabilityOfAtLeastNEvents;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::BinomialProbabilityOfAtLeastNEvents>& Cephei::QL::Experimental::Credit::CBinomialProbabilityOfAtLeastNEvents::GetHandle ()
{
	if (_phBinomialProbabilityOfAtLeastNEvents == NULL)
	{
		_phBinomialProbabilityOfAtLeastNEvents = new Handle<QuantLib::BinomialProbabilityOfAtLeastNEvents> (*_ppBinomialProbabilityOfAtLeastNEvents);
	}
	return *_phBinomialProbabilityOfAtLeastNEvents;
}
#endif
bool Cephei::QL::Experimental::Credit::CBinomialProbabilityOfAtLeastNEvents::HasNative () 
{
	return (_ppBinomialProbabilityOfAtLeastNEvents != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Experimental::Credit::IBinomialProbabilityOfAtLeastNEvents^ Cephei::QL::Experimental::Credit::CBinomialProbabilityOfAtLeastNEvents_Factory::Create (Int32 n)
{
    return gcnew CBinomialProbabilityOfAtLeastNEvents ( n);
}
